package com.myx.zookeeper.curator.lock;

import com.myx.zookeeper.curator.ZookeeperConstant;

/**
 * 描述:锁测试
 * @author: myx
 * @date: 2018/11/23
 * Copyright © 2018-hotpot. All rights reserved.
 */
public class LockTest implements  Runnable{

    Lock wkLock=new Lock(ZookeeperConstant.connectString,"/wklock");
     static int i=0;

    public static void main(String[] args) throws InterruptedException {

        LockTest lockTest2=new LockTest();
        Thread t1= new Thread(lockTest2);
        Thread t2=  new Thread(lockTest2);
        t1.start();t2.start();
        t1.join();t2.join();
        System.out.println(i);

    }



        @Override
        public void run() {
            try {
                for(int j=0;j<300;j++){
                    wkLock.lock();
                    i++;
                    wkLock.unlock();
                }

            } catch (Exception e) {
                e.printStackTrace();
            }


    }
}
